﻿using BCCommon.Enums;
using BCData.WeChatComponent.WeChatMessageRecord;
using BCEntity.WeChatComponent.WeChatMessageRecord;
using System;
using System.Collections.Generic;
using System.Text;
using WeChatSDK.WeChatDto.Conversation.ReceivingMessage;

namespace BCService.WeChatComponent.WeChatHandleService.LinkMessageService
{
    /// <summary>
    /// 微信连接消息处理
    /// </summary>
    public class LinkMessageService : IWeChatMessageHandle
    {
        private readonly IWeChatMessageRecordData weChatMessageRecordData;

        public LinkMessageService(IWeChatMessageRecordData weChatMessageRecordData)
        {
            this.weChatMessageRecordData = weChatMessageRecordData;
        }

        public string HandleMessage(ReceivingMessageDto message)
        {
            LinkMessageDto linkMessageDto = (LinkMessageDto)message;
            WeChatMessageRecordEntity weChatMessageRecordEntity = this.RecordReceivingMessage(linkMessageDto);
            string response = "success";
            return response;
        }

        private WeChatMessageRecordEntity RecordReceivingMessage(LinkMessageDto linkMessageDto)
        {
            WeChatMessageRecordEntity entity = new WeChatMessageRecordEntity()
            {
                ToUserName = linkMessageDto.ToUserName,
                FromUserName = linkMessageDto.FromUserName,
                MessageType = WeChatMessageType.Link,
                MessageId = linkMessageDto.MsgId,
                Title = linkMessageDto.Title,
                Description = linkMessageDto.Description,
                Url = linkMessageDto.Url,
                IsReply = false
            };
            return this.weChatMessageRecordData.Add(entity);
        }
    }
}
